//
//  WKUserInfo.swift
//  NewDelivery
//
//  Created by 天下宅 on 2016/11/11.
//  Copyright © 2016年 天下宅. All rights reserved.
//

import UIKit
import SwiftyJSON
class WKUserInfo: NSObject {
    var address:String!//配送员地址
    var admin_id:String!//区域管理标识
    var username:String!//用户名
    var phone:String!//电话
    var email:String!//邮箱

    var group:String!//分组
    var score:String!//积分?
    var userType:String!//用户样式
    var cost:String!//消费
    var status:String!//状态
    var uid:String!//用户标识
    var md_flag:String!//上线时间?
    var shopcost:String!//商户余额
    var sex:String!//用户性别
    var wxopenid:String!//微信id
    var shopid:String!//店铺id
    var token:String!//token
    
    var logoURL:URL?//用户头像 + 1
    var createTime_format:String!
    var loginTime_format:String!

    private var logo:String?//用户头像
    private var createTime:String!//创建时间
    private var loginTime:String!//登录时间
    //使用
    static let shared : WKUserInfo = {
        let userinfo = WKUserInfo()
        return userinfo
    }()
    //构建
    static func sharedInstance(WithDict dict:[String:JSON]) -> WKUserInfo
    {
        let userinfo = self.shared
        userinfo.set(WithDict: dict)
        return userinfo
    }
    
    func set(WithDict dict:[String:JSON]) {
        
        print(dict)
        token = dict["accesstoken"]!.stringValue
        uid = dict["uid"]!.stringValue
        address = dict["address"]!.stringValue
        email = dict["email"]!.stringValue
        username = dict["username"]!.stringValue
        phone = dict["phone"]!.stringValue
        admin_id = dict["admin_id"]!.stringValue
        createTime = dict["creattime"]!.stringValue
        loginTime = dict["logintime"]!.stringValue
        group = dict["group"]!.stringValue
        score = dict["score"]!.stringValue
        userType = dict["usertype"]!.stringValue
        cost = dict["cost"]!.stringValue
        status = dict["status"]!.stringValue
        md_flag = dict["md_flag"]!.stringValue
        shopcost = dict["shopcost"]!.stringValue
        sex = dict["sex"]!.stringValue
        logo = dict["logo"]!.stringValue
        wxopenid = dict["wxopenid"]!.stringValue
        shopid = dict["shopid"]!.stringValue
        
        logoURL = URL.init(string: logo!)
        createTime_format = String.timeStampToString(timeStamp: createTime)
        loginTime_format = String.timeStampToString(timeStamp: loginTime)
    }
}
